<?php
namespace app\index\domain;

class Base implements \ArrayAccess
{
    protected $_map;
    static protected $tags;

    /**
     * 实现ArrayAccess
     */
    public function offsetGet($key)
    {
        if(isset($this->_map[$key]))
            return $this->_map[$key];
        $function = 'get'.ucfirst($key);
        if(method_exists($this, $function))
            return $this->$function();
        if(method_exists($this, 'valueGet')){
            $result = $this->valueGet($key);
            if(isset($result))
                return $result;
        }
        return null;
    }
    
    public function offsetSet($key, $value)
    {
        if(is_null($key))
            $_map[] =   $value;
        else
            $_map[$key] =   $value;
    }
    
    public function offsetExists($key)
    {
        $value  = $this->offsetGet($key);
        $result = isset($value);
        return $result;
    }
    
    public function offsetUnset($key)
    {
        $_map[$key] = null;
    }

    public function getTags()
    {
        $class = get_class($this);
        return $class::$tags;
    }
}

